package org.tong.distId;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.IdUtil;

public class SnowFlakeUtil {
    private Long workId = 0L;
    private Long datacenterId = 1L;

    private Snowflake snowflake;

    public SnowFlakeUtil() {
        System.out.println("当前机器的workId是：" + workId);
        snowflake = IdUtil.createSnowflake(workId, datacenterId);
    }

    public synchronized Long createId() {
        return snowflake.nextId();
    }


    public static void main(String[] args) {
        SnowFlakeUtil snowFlakeUtil = new SnowFlakeUtil();
        long start = System.currentTimeMillis();
        for (int i=0;i<1000000;i++){
            snowFlakeUtil.createId();
            //System.out.println(snowFlakeUtil.createId());
        }
        System.out.println(System.currentTimeMillis()-start);
    }

}
